package com.psbc.springbootstudydemo1.handler;

import com.psbc.springbootstudydemo1.utils.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

//@RestControllerAdvice
@ControllerAdvice
public class CustomExtHandler {
//    @ExceptionHandler(value = Exception.class)
//    JsonData handlerException(Exception e, HttpServletRequest request){
//        return JsonData.buildError("服务器出现了错误",-2);
//    }
    @ExceptionHandler(value = Exception.class)
    Object handelException(Exception e,HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error.html");
        System.out.println(e.getMessage());
        modelAndView.addObject("msg",e.getMessage());
        return modelAndView;
    }

}
